<?php
/* SVN FILE: $Id: cp_skin_plugin_transfer.php 260 2010-01-21 22:38:54Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* Transfer plugin ACP html
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 260 $
* @lastrevision $Date: 2010-01-21 22:38:54 +0000 (Thu, 21 Jan 2010) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2010-01-21 22:38:54 +0000 (Thu, 21 Jan 2010) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/plugins/transfer/skin_cp/cp_skin_plugin_transfer.php $
*/

class cp_skin_plugin_transfer extends output
{

/**
 * Prevent our main destructor being called by this class
 *
 * @access	public
 * @return	void
 */
public function __destruct()
{
}

/**
 * Manage all the permissions
 *
 * @access	public
 * @return	string	HTML
 */
public function managePermissions() {

$permissionShow = array(
						'anonymous' => $this->lang->words['permission_anon'],
						'money' => sprintf($this->lang->words['permission_money'], $this->settings['market_currency']),
						);
$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['manage_permissions']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin=transfer&amp;action=permissions&amp;do=add'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='' />
				{$this->lang->words['add_permission_set']}
			</a>
		</li>
	</ul>
</div>
<div class='information-box'>
	{$this->lang->words['permission_information']}
</div>
<br />
<div id='manageAllowPermission'>
	<div class='acp-box'>
		<h3>{$this->lang->words['allowed_permissions']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['group_name']}</th>
				<th>{$this->lang->words['permission_type']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
if(is_array($this->caches['ibm_transfer_perm']['allow']) and count($this->caches['ibm_transfer_perm']['allow']))
{
	foreach($this->caches['ibm_transfer_perm']['allow'] as $option => $groupPerm)
	{
		foreach($groupPerm as $option => $permission)
		{
			if($option == 'item')
			{
				foreach($allowed as $itemID => $permItem)
				{
					if($itemID == 'all')
					{
						$itemName = $this->lang->words['permission_all_items'];
					}
					else
					{
						$itemName = sprintf($this->lang->words['permission_item_x'], $this->caches['market_items'][$itemID]['item_name']);
					}
					$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$permItem['group_id']]['g_title']}</td>
				<td>{$itemName}</td>
				<td>
					<img class='ipbmenu' id="menum-{$permItem['group_id']}-{$option}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$permItem['group_id']}-{$option}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=deny&amp;group={$permItem['group_id']}&amp;option={$permItem['p_option']}'>{$this->lang->words['change_to_deny']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=delete&amp;group={$permItem['group_id']}&amp;option={$permItem['p_option']}'>{$this->lang->words['delete_permission']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
				}
			}
			else
			{
				$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$permission['group_id']]['g_title']}</td>
				<td>{$permissionShow[$option]}</td>
				<td>
					<img class='ipbmenu' id="menum-{$permission['group_id']}-{$option}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$permission['group_id']}-{$option}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=deny&amp;group={$permission['group_id']}&amp;option={$permission['p_option']}'>{$this->lang->words['change_to_deny']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=delete&amp;group={$permission['group_id']}&amp;option={$permission['p_option']}'>{$this->lang->words['delete_permission']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
			}
		}
	}
}
else
{
	$IPBHTML .= <<<EOF
			<tr>
				<td colspan='5' style='text-align: center'><strong>{$this->lang->words['no_allowed_permissions_added']}</strong></td>
			</tr>

EOF;
}

$IPBHTML .= <<<EOF
		</table>
	</div>
</div>
<br />
<div id='manageDenyPermission'>
	<div class='acp-box'>
		<h3>{$this->lang->words['denied_permissions']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['group_name']}</th>
				<th>{$this->lang->words['permission_type']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
if(is_array($this->caches['ibm_transfer_perm']['deny']) and count($this->caches['ibm_transfer_perm']['deny']))
{
	foreach($this->caches['ibm_transfer_perm']['deny'] as $groupPerm)
	{
		foreach($groupPerm as $option => $permission)
		{
			if($option == 'item')
			{
				foreach($allowed as $itemID => $permItem)
				{
					if($itemID == 'all')
					{
						$itemName = $this->lang->words['permission_all_items'];
					}
					else
					{
						$itemName = sprintf($this->lang->words['permission_item_x'], $this->caches['market_items'][$itemID]['item_name']);
					}
					$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$permItem['group_id']]['g_title']}</td>
				<td>{$itemName}</td>
				<td>
					<img class='ipbmenu' id="menum-{$permission['group_id']}-{$option}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$permission['group_id']}-{$option}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=allow&amp;group={$permItem['group_id']}&amp;option={$permItem['p_option']}'>{$this->lang->words['change_to_allow']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=delete&amp;group={$permItem['group_id']}&amp;option={$permItem['p_option']}'>{$this->lang->words['delete_permission']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
				}
			}
			else
			{
				$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$permission['group_id']]['g_title']}</td>
				<td>{$permissionShow[$option]}</td>
				<td>
					<img class='ipbmenu' id="menum-{$permission['group_id']}-{$option}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$permission['group_id']}-{$option}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=allow&amp;group={$permission['group_id']}&amp;option={$permission['p_option']}'>{$this->lang->words['change_to_allow']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permission&amp;do=delete&amp;group={$permission['group_id']}&amp;option={$permission['p_option']}'>{$this->lang->words['delete_permission']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
			}
		}
	}
}
else
{
	$IPBHTML .= <<<EOF
			<tr>
				<td colspan='5' style='text-align: center'><strong>{$this->lang->words['no_denied_permissions_added']}</strong></td>
			</tr>

EOF;
}

$IPBHTML .= <<<EOF
		</table>
	</div>
</div>

EOF;

return $IPBHTML;
}

/**
 * Adding permission form
 *
 * @access	public
 * @return	string	HTML
 */
public function addPermissionForm() {

$allowed = array();
$allowed[] = array(0,$this->lang->words['deny']);
$allowed[] = array(1,$this->lang->words['allow']);
$option = array();
$option[] = array('anonymous', $this->lang->words['permission_anon']);
$option[] = array('money', sprintf($this->lang->words['permission_money'], $this->settings['market_currency']));
$option[] = array('item-all', $this->lang->words['permission_all_items']);
$option[] = array('0', '----------------------------------------');
foreach($this->caches['market_items'] as $item)
{
	$option[] = array('item-'.$item['item_id'], sprintf($this->lang->words['permission_item_x'], $item['item_name']));
}
$form['group_id'] = ipsRegistry::getClass('output')->generateGroupDropdown('group_id', 0);
$form['p_option'] = ipsRegistry::getClass('output')->formDropdown('p_option', $option, '0');
$form['allowed'] = ipsRegistry::getClass('output')->formDropdown('allowed', $allowed);

$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['add_permission_set']}</h2>
</div>

<div id='transferPermissionFormPage'>
	<form method='post' action='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=permissions&amp;do=insert' id='transferPermissionForm'>
		<input type='hidden' name='_admin_auth_key' value='{$this->registry->adminFunctions->getSecurityKey()}' />
		<div class='acp-box'>
			<h3>{$this->lang->words['add_permission_set']}</h3>
			<ul class='acp-form alternate_rows'>
				<li>
					<label>{$this->lang->words['which_type_of_permission']}</label>
					{$form['allowed']}
				</li>
				<li>
					<label>{$this->lang->words['which_group_apply_to']}</label>
					{$form['group_id']}
				</li>
				<li>
					<label>{$this->lang->words['what_does_apply_to']}</label>
					{$form['p_option']}
				</li>
			</ul>
			<div class='acp-actionbar'>
				<div class='centeraction'>
					<input type='submit' value='{$this->lang->words['add_permission_submit']}' class='button primary'>
				</div>
			</div>
		</div>
	</form>
</div>

EOF;

return $IPBHTML;
}

/**
 * Manage all the fees
 *
 * @access	public
 * @return	string	HTML
 */
public function manageFees() {

$feeShow = array(
					'anonymous' => $this->lang->words['fee_anonymous'],
					'money' => sprintf($this->lang->words['fee_money'], $this->settings['market_currency']),
				);
$IPBHTML .= <<<EOF
<div class='section_title'>
	<h2>{$this->lang->words['manage_fees']}</h2>
	<ul class='context_menu'>
		<li>
			<a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin=transfer&amp;action=permissions&amp;do=add'>
				<img src='{$this->settings['skin_acp_url']}/_newimages/icons/add.png' alt='' />
				{$this->lang->words['add_transfer_fee']}
			</a>
		</li>
	</ul>
</div>
<div id='manageFees'>
	<div class='acp-box'>
		<h3>{$this->lang->words['acp_fees']}</h3>
		<table width='100%' cellpadding='0' cellspacing='0' border='0' class='alternate_rows'>
			<tr>
				<th>{$this->lang->words['group_name']}</th>
				<th>{$this->lang->words['applies_to']}</th>
				<th>{$this->lang->words['how_much']}</th>
				<th style='width:1px;min-width:1%;white-space:nowrap'>{$this->lang->words['options']}</th>
			</tr>

EOF;
if(is_array($this->caches['ibm_transfer_fees']) and count($this->caches['ibm_transfer_fees']))
{
	foreach($this->caches['ibm_transfer_fees'] as $groupFees)
	{
		foreach($groupFees as $type => $fees)
		{
			if($type == 'item')
			{
				foreach($fees as $itemID => $itemFees)
				{
					if($itemID == 'all')
					{
						$itemName = $this->lang->words['fee_all_items'];
					}
					else
					{
						$itemName = sprintf($this->lang->words['fee_item_x'], $this->caches['market_items'][$itemID]['item_name']);
					}
					foreach($itemFees as $fee)
					{
						$types = explode("-",$fee['fee_type']);
						$feeAmount = $fee['apply'] == 'percent' ? sprintf($this->lang->words['acp_item_fee_'.$types[2]], marketFormatter::numberFormat($fee['amount'],10)) : sprintf($this->lang->words['acp_flat_fee'], marketFormatter::formatCurrency($fee['amount']));
						$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$fee['group_id']]['g_title']}</td>
				<td>{$itemName}</td>
				<td>{$feeAmount}</td>
				<td>
					<img class='ipbmenu' id="menum-{$fee['fee_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$fee['fee_id']}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=fees&amp;do=edit&amp;fee={$fee['fee_id']}}'>{$this->lang->words['edit_fee']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=fess&amp;do=delete&amp;fee={$fee['fee_id']}'>{$this->lang->words['delete_fee']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
					}
				}
			}
			else
			{
				foreach($fees as $fee)
				{
					$feeAmount = $fee['apply'] == 'percent' ? sprintf($this->lang->words['acp_percent_fee'], marketFormatter::numberFormat($fee['amount'],10)) : sprintf($this->lang->words['acp_flat_fee'], marketFormatter::formatCurrency($fee['amount']));
					$IPBHTML .= <<<EOF
			<tr>
				<td>{$this->caches['group_cache'][$fee['group_id']]['g_title']}</td>
				<td>{$feeShow[$option]}</td>
				<td>{$feeAmount}</td>
				<td>
					<img class='ipbmenu' id="menum-{$fee['fee_id']}" src='{$this->settings['skin_acp_url']}/_newimages/menu_open.png' alt='{$this->lang->words['frm_options']}' /> &nbsp;
					<ul class='acp-menu' id='menum-{$fee['fee_id']}_menucontent'>
						<li class='icon edit'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=fees&amp;do=edit&amp;fee={$fee['fee_id']}}'>{$this->lang->words['edit_fee']}</a></li>
						<li class='icon delete'><a href='{$this->settings['base_url']}module=plugin&amp;section=plugin&amp;plugin={$this->request['plugin']}&amp;action=fess&amp;do=delete&amp;fee={$fee['fee_id']}'>{$this->lang->words['delete_fee']}</a></li>
					</ul>
				</td>
			</tr>

EOF;
				}
			}
		}
	}
}
else
{
	$IPBHTML .= <<<EOF
			<tr>
				<td colspan='5' style='text-align: center'><strong>{$this->lang->words['no_fees_added']}</strong></td>
			</tr>

EOF;
}

$IPBHTML .= <<<EOF
		</table>
	</div>
</div>

EOF;

return $IPBHTML;
}

}